package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.ToolUrl;
import com.prs.crm.service.sys.ToolUrlService;

public class ToolUrlAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private ToolUrl toolUrl;
	private ToolUrlService toolUrlService;
	private String serCode;
	
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public ToolUrl getToolUrl() {
		return toolUrl;
	}
	public void setToolUrl(ToolUrl toolUrl) {
		this.toolUrl = toolUrl;
	}
	public ToolUrlService getToolUrlService() {
		return toolUrlService;
	}
	public void setToolUrlService(ToolUrlService toolUrlService) {
		this.toolUrlService = toolUrlService;
	}

	@Action("editToolUrl")
	public String editToolUrl(){
		this.toolUrl=this.getToolUrlService().getToolUrl(serCode);
		return SUCCESS;
	}
	@Action(value = "saveToolUrl", results = {
			@Result(name = "success", type = "redirect", location = "editToolUrl?serCode=${toolUrl.getType()}"),
			@Result(name = "error", type = "chain", location = "editToolUrl?serCode=${toolUrl.getType()}")})
	public String saveToolUrl(){
		ToolUrl tool=this.getToolUrlService().getToolUrl("tu01");
		if(tool==null){
			tool=new ToolUrl();
			tool.setType("tu01");
			tool.setAreaCode(toolUrl.getAreaCode());
			tool.setCompanyUrl(toolUrl.getCompanyUrl());
			tool.setIntermationTime(toolUrl.getIntermationTime());
			tool.setPlanceFlight(toolUrl.getPlanceFlight());
			tool.setTrainMoment(toolUrl.getTrainMoment());
			this.getToolUrlService().save(tool);
		}else{
			this.getToolUrlService().submit(tool);
		}
		toolUrl=tool;
		return SUCCESS;
	}
	
	@Action("listTrainMoment")
	public String listTrainMoment(){
		this.toolUrl = this.getToolUrlService().getToolUrl("tu01");
		return SUCCESS;
	}
	@Action("listPlanceFlight")
	public String listPlanceFlight(){
		this.toolUrl = this.getToolUrlService().getToolUrl("tu01");
		return SUCCESS;
	}
	@Action("listAreaCode")
	public String listAreaCode(){
		this.toolUrl = this.getToolUrlService().getToolUrl("tu01");
		return SUCCESS;
	}
	@Action("listIntermationTime")
	public String listIntermationTime(){
		this.toolUrl = this.getToolUrlService().getToolUrl("tu01");
		return SUCCESS;
	}
	@Action("listCompanyUrl")
	public String listCompanyUrl(){
		this.toolUrl = this.getToolUrlService().getToolUrl("tu01");
		return SUCCESS;
	}
}
